package com.sline.ThreadMethod;

public class Demo3_Sleep {
    public static void main(String[] args) throws InterruptedException {
        // demo1();

        new Thread() {
            public void run() {
                for (int i = 0; i < 5; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(this.getName() + " " + "第" + i + "次输出a");
                }
            }
        }.start();

        new Thread() {
            public void run() {
                for (int i = 0; i < 5; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(this.getName() + " " + "第" + i + "次输出b");
                }
            }
        }.start();
    }

    private static void demo1() throws InterruptedException {
        for (int i = 5; i > 0; i--) {
            Thread.sleep(1000);
            System.out.println("倒计时" + i + "秒");
        }
    }
}
